package com.example.demo.pattern.mixpattern.entity.counter;

import com.example.demo.pattern.mixpattern.entity.duck.QuackAble;
import com.example.demo.pattern.mixpattern.observer.Observer;

//鸭叫计数器，装饰者模式
public class QuackCounter implements QuackAble {
    private final QuackAble quackAble;
    static int numberOfQuacks;

    public QuackCounter(QuackAble quackAble) {
        this.quackAble = quackAble;
    }

    //调用叫方法，同时计数
    @Override
    public void quack() {
        quackAble.quack();
        numberOfQuacks++;
    }

    //返回全局鸭叫次数
    public static int getNumberOfQuacks() {
        return numberOfQuacks;
    }

    @Override
    public void registerObserver(Observer observer) {
        quackAble.registerObserver(observer);
    }

    @Override
    public void notifyObservers() {
        quackAble.notifyObservers();
    }
}
